package com.example.demo.utils.encode;

/**
 * 数据库密码的加密和解密
 */
public final class PwdHelper {
    private static final int PWD_LENGTH = 32;
    private static PwdIntf pwdIntf = new AES();

    private PwdHelper() {
    }


    /**
     * 数据库密码解密
     */
    public static String decrypt(String pass) {
        return pwdIntf.decrypt(pass);
    }

    /**
     * 数据库密码解密
     */
    public static String decryptIgnoreException(String pass) {
        try {
            return pwdIntf.decrypt(pass);
        } catch (Exception e) {
            return pass;
        }
    }

    /**
     * 数据库密码加密
     */
    public static String encrypt(String pass)// throws IOException
    {
        return pwdIntf.encrypt(pass);
    }

    public interface PwdIntf {
        String decrypt(String pass);

        String encrypt(String pass);
    }

    public static void main(String[] args) {
        String decrypt = decrypt("KZmk9einNc4Nrdxlx+bgrA==");
        String encrypt = encrypt("antdbt_acc");
        System.out.println(decrypt);
        System.out.println(encrypt);
    }
}
